import { MainMenu } from "../UI/MainMenu";
import DataManager from "../utils/DataSystem/DataManager";
import { StateBlock } from "../utils/StateBlock/StateBlock";
import UIManager from "../utils/UIFramework/UIManager";

export default class AppStateBlock extends StateBlock
{
    protected InitState: typeof StateBlock = AppStateBlock_Loading;
}

class AppStateBlock_StateBase extends StateBlock
{
    public get app() : AppStateBlock {
        return this.parent as AppStateBlock;
    }
}

class AppStateBlock_Loading extends AppStateBlock_StateBase
{
    public async onEnter(): Promise<void> {
        await DataManager.Instance.preloadData();
        this.app.changeState(AppStateBlock_MainMenu);
    }

    public onExit(): void {
        
    }
}

class AppStateBlock_MainMenu extends AppStateBlock_StateBase
{
    public async onEnter(): Promise<void> {
        let menuUI = await UIManager.Instance.OpenUI("mainMenu",UIManager.UI_LAYER.UIPage) as MainMenu;
        menuUI.startGameEvent.AddFunc(
            (app : AppStateBlock)=>{
                app.changeState(AppStateBlock_Game);
            }
        ,this.parent);
    }

    public onExit(): void {
        UIManager.Instance.CloseUI("mainMenu");
    }
}

class AppStateBlock_Game extends AppStateBlock_StateBase
{
    public onEnter(): void {
        UIManager.Instance.OpenUI("game",UIManager.UI_LAYER.UIPage);
        
    }
}